package com.deer.wms.base.system.web;

import com.deer.wms.base.system.model.*;
import com.deer.wms.base.system.model.box.BoxItem;
import com.deer.wms.base.system.model.box.BoxItemCriteria;
import com.deer.wms.base.system.model.box.BoxItemDto;
import com.deer.wms.base.system.model.task.TaskInfo;
import com.deer.wms.base.system.model.task.TaskInfoCriteria;
import com.deer.wms.base.system.service.SluggishOverdueService;
import com.deer.wms.base.system.service.WorkerOrderIssueTimeService;
import com.deer.wms.base.system.service.box.IBoxItemService;
import com.deer.wms.base.system.service.task.ITaskInfoService;
import com.deer.wms.common.annotation.Log;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.enums.BusinessType;
import com.deer.wms.common.utils.DateUtils;
import com.deer.wms.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.common.core.result.Result;
import com.deer.wms.common.core.result.ResultGenerator;
import org.springframework.stereotype.Controller;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.ui.ModelMap;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.page.TableDataInfo;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
* Created by  on 2019/11/21.
*/
@Controller
@RequestMapping("/sluggishOverdue")
public class SluggishOverdueController  extends BaseController{

    private String prefix = "in/boxItem";

    @Autowired
    private SluggishOverdueService sluggishOverdueService;
    @Autowired
    private WorkerOrderIssueTimeService workerOrderIssueTimeService;
    @Autowired
    private IBoxItemService boxItemService;
    @Autowired
    private ITaskInfoService taskInfoService;

    /**
    * 详情
    */
    @GetMapping("/detail")
    public String detail()
    {
        return prefix + "/detail";
    }

    @RequiresPermissions("sluggishOverdue:view")
    @GetMapping()
    public String sluggishOverdue()
    {
        return prefix + "/sluggishOverdue";
    }

    /**
    * 修改
    */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
    SluggishOverdue sluggishOverdue = sluggishOverdueService.findObjectsById(id);
        mmap.put("sluggishOverdue", sluggishOverdue);
        return prefix + "/edit";
    }

    /**
     * 修改保存呆滞过期报表信息
     */
    @RequiresPermissions("in:sluggishOverdue:edit")
    @Log(title = "呆滞过期报表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SluggishOverdue sluggishOverdue)
    {
        return toAjax(sluggishOverdueService.saveSluggishOverdue(sluggishOverdue));
    }


    /**
    * 新增
    */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/addSov";
    }

    /**
     * 新增呆滞过期报表
     */
    @RequiresPermissions("in:sluggishOverdue:add")
    @Log(title = "呆滞过期报表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody SluggishOverdue sluggishOverdue)
    {
        return toAjax(sluggishOverdueService.insertSluggishOverdue(sluggishOverdue));
    }

    /**
     * 删除报表
     */
    @RequiresPermissions("in:sluggishOverdue:remove")
    @Log(title = "报表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {

        return toAjax(sluggishOverdueService.deleteSluggishOverdueByIds(ids));
    }


//    @PostMapping("/add")
//    @ResponseBody
//    public Result add(@RequestBody SluggishOverdue sluggishOverdue) {
//        sluggishOverdueService.insertSluggishOverdue(sluggishOverdue);
//        return ResultGenerator.genSuccessResult();
//    }

    @DeleteMapping("/{id}")
    @ResponseBody
    public Result delete(@PathVariable Integer id) {
        sluggishOverdueService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody SluggishOverdue sluggishOverdue) {
        sluggishOverdueService.update(sluggishOverdue);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/{id}")
    @ResponseBody
    public Result detail(@PathVariable Integer id) {
        SluggishOverdue sluggishOverdue = sluggishOverdueService.findById(id);
        return ResultGenerator.genSuccessResult(sluggishOverdue);
    }

    @PostMapping("/list")
    @ResponseBody
    public  TableDataInfo list(SluggishOverdueCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<SluggishOverdue> list = sluggishOverdueService.findAll();
        return getDataTable(list);
    }

    @PostMapping("/findList")
    @ResponseBody
    public  TableDataInfo findList(SluggishOverdueCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<SluggishOverdueDto> list = sluggishOverdueService.findList(criteria);
        return getDataTable(list);
    }
    @RequiresPermissions("in:sluggishOverdue:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SluggishOverdueCriteria sluggishOverdueCriteria) {
        ExcelUtil<SluggishOverdueDto> util = new ExcelUtil<SluggishOverdueDto>(SluggishOverdueDto.class);
        List<SluggishOverdueDto> sluggishOverdueDtos= sluggishOverdueService.findList(sluggishOverdueCriteria);
        return util.exportExcel(sluggishOverdueDtos, "呆滞过期报表");
    }

}
